package com.cicadasmall.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cicadasmall.common.resp.R;
import com.cicadasmall.system.dto.OauthClientDetailsInputDTO;
import com.cicadasmall.system.dto.OauthClientDetailsQueryDTO;
import com.cicadasmall.system.dto.OauthClientDetailsUpdateDTO;
import com.cicadasmall.data.domain.OauthClientDetailsDO;
import com.cicadasmall.system.service.IOauthClientDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "S-Oauth2客户端管理接口")
@RestController
@RequestMapping("/system/clients")
public class ClientController {
    @Autowired
    private IOauthClientDetailsService oauthClientDetailsService;

    @ApiOperation(value = "oauth客户端列表接口")
    @GetMapping("/list")
    public R<Page<OauthClientDetailsDO>> getPage(OauthClientDetailsQueryDTO oauthClientDetailsQueryDTO) {
        return oauthClientDetailsService.page(oauthClientDetailsQueryDTO);
    }

    @ApiOperation(value = "oauth客户端保存接口")
    @PostMapping
    public R<Boolean> save(@RequestBody @Valid OauthClientDetailsInputDTO oauthClientDetailsInputDTO) {
        return oauthClientDetailsService.save(oauthClientDetailsInputDTO);
    }

    @ApiOperation(value = "oauth客户端更新接口")
    @PutMapping
    public R<Boolean> updateById(@RequestBody @Valid OauthClientDetailsUpdateDTO oauthClientDetailsUpdateDTO) {
        return oauthClientDetailsService.update(oauthClientDetailsUpdateDTO);
    }

    @ApiOperation(value = "oauth客户端详情接口")
    @GetMapping("/{id}")
    public R<OauthClientDetailsDO> getById(@PathVariable Long id) {
        return oauthClientDetailsService.findById(id);
    }

    @ApiOperation(value = "oauth客户端删除接口")
    @DeleteMapping("/{id}")
    public R<Boolean> removeById(@PathVariable Long id) {
        return oauthClientDetailsService.deleteById(id);
    }


}
